package edu.sctu.treebuilder.day01;

/**
 * Created by apple on 05/02/2018.
 */
public enum State {
    StateZero {
        @Override
        void read(StateController controller, CharacterReader reader) {

            char ch = reader.consume();

            switch (ch) {

                case 'a':
                    controller.transition(StateOne);
                    break;

                default:
                    controller.transition(StateThree);
                    break;

            }
        }
    },
    StateOne {
        @Override
        void read(StateController controller, CharacterReader reader) {

            char ch = reader.consume();

            switch (ch) {

                case 'b':
                    break;
                case 'a':
                    controller.transition(StateTwo);
                    break;
                default:
                    controller.transition(StateThree);
                    break;
            }
        }
    },
    StateTwo {
        @Override
        void read(StateController controller, CharacterReader reader) {

            controller.setTerminated(true);
            System.out.println("Match!");
        }
    },
    StateThree {
        @Override
        void read(StateController controller, CharacterReader reader) {

            controller.setTerminated(true);
            System.out.println("UnMatch!");
        }
    };

    abstract void read(StateController controller, CharacterReader reader);
}
